package com.woniuxy.controller;


import com.woniuxy.controller.form.*;
import com.woniuxy.exception.DdException;
import com.woniuxy.service.PawnBrandService;
import com.woniuxy.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hujianying
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/pawnBrand")
@Api(tags = "品牌相关接口")
public class PawnBrandController {

    @Resource
    private PawnBrandService pbs;

    /**
     * 查询所有品牌
     * @param bpf 分页参数
     * @return BrandPageInfo
     */
    @ApiOperation("查询所有品牌")
    @GetMapping("/getAllBrand")
    public Result getAllBrand(BrandPageForm bpf){
        return pbs.getAllBrand(bpf);
    }

    /**
     * 根据品牌名模糊查询
     * @param bpf str
     * @return BrandPageInfo
     */
    @ApiOperation("根据品牌名模糊查询")
    @GetMapping("/getBrandByLike")
    public Result getBrandByLike(BrandPageForm bpf) throws DdException {
        return pbs.getBrandByLike(bpf);
    }

    /**
     * 根据选中的删除
     * @param dbf ischecked
     * @return data为null
     */
    @ApiOperation("根据选中的删除")
    @PostMapping("/deleteBrand")
    public Result deleteBrand(@RequestBody DeleteBrandForm dbf) throws DdException {
        return pbs.deleteBrand(dbf);
    }

    /**
     * 根据brandCode查询
     * @param gobf brandCode
     * @return GetOneBrandInfo
     */
    @ApiOperation("根据brandCode查询")
    @GetMapping("/getBrandByCode")
    public Result getBrandByCode(GetOneBrandForm gobf){
        return pbs.getBrandByCode(gobf);
    }

    /**
     * 修改品牌
     * @param ubf UpdateBrandForm
     * @return data为null
     */
    @ApiOperation("修改品牌")
    @PostMapping("/updateBrand")
    public Result updateBrand(@RequestBody UpdateBrandForm ubf) throws DdException {
        return pbs.updateBrand(ubf);
    }

    /**
     * 新增品牌
     * @param sbf SaveBrandForm
     * @return data为null
     */
    @ApiOperation("新增品牌")
    @PostMapping("/saveBrand")
    public Result saveBrand(@RequestBody SaveBrandForm sbf) throws DdException {
        return pbs.saveBrand(sbf);
    }

    /***
     * 根据大类code查询对应的所有品牌
     * @param gbbccf
     * @return
     */
    @ApiOperation("根据大类code查询对应的所有品牌")
    @GetMapping("/getBrandByCatCode")
    public Result getBrandByCatCode(GetBrandByCatCodeForm gbbccf){
        System.out.println(pbs.getBrandByCatCode(gbbccf));
        return pbs.getBrandByCatCode(gbbccf);
    }
}

